package com.hs.sfzy.controller;

import com.hs.sfzy.entity.ClassAnswer;
import com.hs.sfzy.service.ClassAnswerService;
import com.hs.sfzy.until.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName ClassAnswerController
 * @Description TODO
 * @Author Chen
 * @Date 2025年08月13日 14:24
 * @Version 1.0
 */
@RestController
@RequestMapping("/classAnswer")
public class ClassAnswerController {
    @Autowired
    private ClassAnswerService classAnswerService;

    @GetMapping("/question/{questionId}")
    public R getClassAnswerByQuestionId(@PathVariable("questionId") Integer questionId) {
        List<ClassAnswer> classAnswerByQuestionId = classAnswerService.getClassAnswerByQuestionId(questionId);
        return R.ok(classAnswerByQuestionId);
    }

    @GetMapping("/user/{userId}")
    public R getClassAnswerByUserId(@PathVariable("userId") Integer userId) {
        List<ClassAnswer> classAnswerByUserId = classAnswerService.getClassAnswerByUserId(userId);
        return R.ok(classAnswerByUserId);
    }

    @PostMapping("add")
    public R addClassAnswer(@RequestBody ClassAnswer classAnswer) {
        Integer addClassAnswer = classAnswerService.addClassAnswer(classAnswer);
        return R.ok(addClassAnswer);
    }
}
